package com.cj.image.controller;

import com.cj.image.bean.ImageTagBean;
import com.cj.image.bean.TagInfo;
import com.cj.image.mapper.TagMapper;
import com.cj.image.service.TagService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Comparator;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("tag")
public class TagController {
    @Autowired
    private TagMapper tagMapper;

    @Autowired
    private TagService tagService;

    @GetMapping("/getTagInfo/{tag_level}")
    public List<TagInfo> getTagInfo(@PathVariable int tag_level) {
        return tagMapper.getTagInfoByLevel(tag_level+"");
    }

    @GetMapping("/getTagInfoByTagId/{tag_id}")
    public List<TagInfo> getTagInfo(@PathVariable String tag_id) {
        return tagMapper.getTagInfoByTagId(tag_id);
    }

    @GetMapping("/getTagLine/{image_id}")
    public String getTagLine(@PathVariable String image_id) {
        List<String> tagLine = tagMapper.getTagLine(image_id);
        return StringUtils.join(tagLine,"  ");
    }

    @PostMapping("/addTagInfo")
    public void addTagInfo(@RequestBody TagInfo tagInfo) {
        tagService.addTagInfo(tagInfo);
    }

    @GetMapping("/deleteTagInfo/{tag_id}")
    public void deleteTagInfo(@PathVariable String tag_id) {
        tagMapper.deleteTagInfo(tag_id);
    }

    @PostMapping("/addImageTag")
    public void addTagInfo(@RequestBody List<ImageTagBean> imageTagBeans) {
        tagService.addImageTag(imageTagBeans);
    }

    @PostMapping("/deleteImageTag")
    public void deleteImageTag(@RequestBody List<ImageTagBean> imageTagBeans) {
        tagService.deleteImageTag(imageTagBeans);
    }
}
